<?php
namespace common\records;
use Yii;
use yii\db\ActiveRecord;

class Share extends ActiveRecord
{
    /**
    ** @return string 返回该AR类关联的数据表名
    **/
    public static function tableName()
    {
        return 'share';
    }

    public function rules()
    {
        return [
            [['uid', 'photo','toy_name'], 'required'],
            [['achievement_id'], 'integer'],
            [['share_time','uid','photo','toy_name'], 'string'],
            ];
    }

    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => '用户ID',
            'photo' => '娃娃图片',
            'share_time' => '分享时间',
            'achievement_id' => '成就ID',
            'toy_name' => '娃娃名字',
            'nick' => '用户昵称',
            'toy_photo' => '娃娃图片',
            ];
    }
    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            if ($insert == true) {
                $this->share_time= date('Y-m-d H:i:s');
            }
            return true;
        }
        return false;
    }
}
